import random

from  pynput import keyboard
from playsound import playsound
from  threading import Thread
#记录当前用户按了多少下键盘
count= 0
soundList = ['','']
def onRelease(key):
    global count
    count += 1
    print(key)
    if count % 20 == 0:
        print("播放音频")
        i = random.randint(0,len(soundList)-1)
        # 为了避免播放音频卡顿，创建一个单独线程执行
        t = Thread(target=playsound,args=soundList[i])
        t.start()
        # playsound(soundList[i])


#捕捉键盘按键
listener = keyboard.Listener(on_release=onRelease)
listener.start()
listener.join()